package com.ymatou.iapi.trading.userquery.testcase;

import java.math.BigDecimal;
import java.util.stream.Collectors;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.parameter.enums.CancelOrderTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.parameter.req.AgreeRefundReq;
import com.ymatou.iapi.optrade.parameter.req.ApplyRefundReq;
import com.ymatou.iapi.optrade.parameter.vo.SalesRefundInfoVo;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.optrade.service.AgreeRefundCall;
import com.ymatou.iapi.optrade.service.RefundService;
import com.ymatou.iapi.synctrade.parameter.mongo.Order;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymatou.query.seller.trading.api.parameter.GetSingleOrderInfoBean;
import com.ymatou.query.seller.trading.api.parameter.GetSingleOrderInfoResponse;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.common.entitie.OrderItemInfo;
import com.ymttest.common.entitie.OrderItemInfoExt;
import com.ymttest.common.order.userquery.SingleOrderInfoBuilder;
import com.ymttest.common.order.userquery.client.ProductClient;
import com.ymttest.common.order.userquery.client.SellerInfoClient;
import com.ymttest.common.order.userquery.model.vo.SingleOrderInfo;
import com.ymttest.database.mongo.OrderQueryWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 获取单个订单信息 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetSingleOrderInfo {

	private static GetSingleOrderInfoBean gsoibean;
	private static com.ymatou.iapi.trading.userquery.service.GetSingleOrderInfoCall gsoicall;

	private ProductClient productClient;
	private SellerInfoClient sellerInfoClient;
	
	private static Integer userId = 20238699;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取单个订单信息");
	}

	@Before
	public void caseUp() {
		gsoibean = new GetSingleOrderInfoBean();
		gsoicall = new com.ymatou.iapi.trading.userquery.service.GetSingleOrderInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(gsoicall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verify() throws JSONException {
		GetSingleOrderInfoResponse expectedResponse = new GetSingleOrderInfoResponse();
		ConstructExpectedResponse(expectedResponse);
		SingleOrderInfo expect = expectedResponse.getOrderInfo();
		SingleOrderInfo actual = gsoicall.getSingleOrderInfo();
		
		int diff = YMTDateUtil.diffMs(actual.getAutoReceiveTime(), YMTDateUtil
				.parseDate("1900-01-01T00:00:00", YMTDateUtil.YMDTHMS_STRING));
		actual.setAutoReceiveEnabled(diff != 0);
		
		if (expect == null) {
			DataUtil.verify(expect, actual, "验证OrderInfo == null");
		} else {
			boolean notnull = actual != null;
			DataUtil.verify(true, notnull, "验证OrderInfo != null");
			if (notnull) {
				verifyOrderInfo(expect, actual);
			}
		}
	}

	private void verifyOrderInfo(SingleOrderInfo expect, SingleOrderInfo actual) {
		DataUtil.verify(expect.getTotalRefundThirdPartyDiscount(),
				actual.getTotalRefundThirdPartyDiscount(),
				"验证OrderInfo.TotalRefundThirdPartyDiscount");

		DataUtil.verify(
				expect.getIsFirstOrder() == null ? false : expect
						.getIsFirstOrder(),
				actual.getIsFirstOrder() == null ? false : actual
						.getIsFirstOrder(), "验证OrderInfo.IsFirstOrder");
		DataUtil.verify(expect.isPreSaleOrder(), actual.isPreSaleOrder(),
				"验证OrderInfo.PreSaleOrder");
		DataUtil.verify(expect.getDiscountOfThirdParty(),
				actual.getDiscountOfThirdParty(),
				"验证OrderInfo.DiscountOfThirdParty");
		DataUtil.verifyDateEquals(expect.getAcceptTime(),
				actual.getAcceptTime(), "验证OrderInfo.AcceptTime");
		DataUtil.verify(expect.getAddress(), actual.getAddress(),
				"验证OrderInfo.Address");
		// DataUtil.verifyDateEquals(expect.getAddTime(), actual.getAddTime(),
		// "验证OrderInfo.AddTime");
		DataUtil.verifyDateEquals(expect.getApplyPostPayTime(),
				actual.getApplyPostPayTime(), "验证OrderInfo.ApplyPostPayTime");
		DataUtil.verify(expect.getAutoCancelOrderHours(),
				actual.getAutoCancelOrderHours(),
				"验证OrderInfo.AutoCancelOrderHours");
		if (DataUtil.isNullOrEmpty(expect.getBillCodeList())) {
			DataUtil.verify(true,
					DataUtil.isNullOrEmpty(actual.getBillCodeList()),
					"验证OrderInfo.BillCodeList == null或者空列表");
		} else {
			boolean goon = DataUtil.isNullOrEmpty(actual.getBillCodeList()) == false;
			DataUtil.verify(true, goon,
					"验证OrderInfo.BillCodeList != null且不是空列表");
			if (goon) {
				for (String s : expect.getBillCodeList()) {
					DataUtil.verify(true, actual.getBillCodeList().contains(s),
							"验证OrderInfo.BillCodeList中存在值=[" + s + "]");
				}
			}
		}

		DataUtil.verify(expect.getBuyerId(), actual.getBuyerId(),
				"验证OrderInfo.BuyerId");
		DataUtil.verify(expect.getBuyerLoginId(), actual.getBuyerLoginId(),
				"验证OrderInfo.BuyerLoginId");
		DataUtil.verify(expect.getBuyerNickName(), actual.getBuyerNickName(),
				"验证OrderInfo.BuyerNickName");
		DataUtil.verifyDateEquals(expect.getCancelTime(),
				actual.getCancelTime(), "验证OrderInfo.CancelTime");

		DataUtil.verifyDateEquals(expect.getConfirmedTime(),
				actual.getConfirmedTime(), "验证OrderInfo.ConfirmedTime");
		DataUtil.verify(expect.getCouponCode(), actual.getCouponCode(),
				"验证OrderInfo.CouponCode");
		DataUtil.verify(expect.getCouponValue(), actual.getCouponValue(),
				"验证OrderInfo.CouponValue");
		DataUtil.verify(expect.isCredited(), actual.isCredited(),
				"验证OrderInfo.Credited");
		DataUtil.verifyDateEquals(expect.getDelayReceiveFrozenTime(),
				actual.getDelayReceiveFrozenTime(),
				"验证OrderInfo.DelayReceiveFrozenTime");
		DataUtil.verifyDateEquals(expect.getDelayReceiveUpdateTime(),
				actual.getDelayReceiveUpdateTime(),
				"验证OrderInfo.DelayReceiveUpdateTime");
		DataUtil.verify(expect.getDelayReceiveUserId(),
				actual.getDelayReceiveUserId(),
				"验证OrderInfo.DelayReceiveUserId");
		DataUtil.verify(expect.getDiscount(), actual.getDiscount(),
				"验证OrderInfo.Discount");
		DataUtil.verifyDateEquals(expect.getDispatchTime(),
				actual.getDispatchTime(), "验证OrderInfo.DispatchTime");
		DataUtil.verifyDateEquals(expect.getDispathTime(),
				actual.getDispathTime(), "验证OrderInfo.DispathTime");
		DataUtil.verify(expect.getEmail(), actual.getEmail(),
				"验证OrderInfo.Email");
		DataUtil.verify(expect.getFirstPay(), actual.getFirstPay(),
				"验证OrderInfo.FirstPay");
		DataUtil.verify(expect.getFreight(), actual.getFreight(),
				"验证OrderInfo.Freight");
		DataUtil.verify(expect.isAutoReceiveEnabled(),
				actual.isAutoReceiveEnabled(),
				"验证OrderInfo.IsAutoReceiveEnabled");
		DataUtil.verify(expect.isShippedByXlobo(), actual.isShippedByXlobo(),
				"验证OrderInfo.IsShippedByXlobo");
		DataUtil.verify(expect.getLeaveWord(), actual.getLeaveWord(),
				"验证OrderInfo.LeaveWord");
		DataUtil.verify(expect.getLogisticsType(), actual.getLogisticsType(),
				"验证OrderInfo.LogisticsType");
		DataUtil.verify(expect.getNeedPrePayAmountOfCash(),
				actual.getNeedPrePayAmountOfCash(),
				"验证OrderInfo.NeedPrePayAmountOfCash");
		DataUtil.verify(expect.getOrderDiscount(), actual.getOrderDiscount(),
				"验证OrderInfo.OrderDiscount");
		DataUtil.verify(expect.getOrderId(), actual.getOrderId(),
				"验证OrderInfo.OrderId");
		if (expect.getOrderItemList() == null) {
			DataUtil.verify(expect.getOrderItemList(),
					actual.getOrderItemList(), "验证OrderInfo.OrderItemList=null");
		} else {
			if (!DataUtil.isNullOrEmpty(expect.getOrderItemList())) {
				DataUtil.verify(expect.getOrderItemList().size(), actual
						.getOrderItemList().size(),
						"验证OrderInfo.OrderItemList.size()");
				boolean equal = expect.getOrderItemList().size() == actual
						.getOrderItemList().size();
				if (equal) {
					for (OrderItemInfo exp : expect.getOrderItemList()) {
						String expPid = exp.getProductId();
						boolean exists = actual.getOrderItemList().stream()
								.anyMatch(x -> x.getProductId().equals(expPid));
						DataUtil.verify(true, exists, "验证ProductId=[" + expPid
								+ "]是否存在于OrderInfo.OrderItemList.size()");
						if (exists) {
							OrderItemInfo act = actual
									.getOrderItemList()
									.stream()
									.filter(x -> x.getProductId()
											.equals(expPid))
									.collect(Collectors.toList()).get(0);
							verifyOrderItemList(exp, act, expPid);
						}
					}
				}
			}
		}
		DataUtil.verify(expect.getOrderPrice(), actual.getOrderPrice(),
				"验证OrderInfo.OrderPrice");
		DataUtil.verify(expect.isPaidInFull(), actual.isPaidInFull(),
				"验证OrderInfo.PaidInFull");
		DataUtil.verifyDateEquals(expect.getPaidTime(), actual.getPaidTime(),
				"验证OrderInfo.PaidTime");
		DataUtil.verify(expect.getPhone(), actual.getPhone(),
				"验证OrderInfo.Phone");
		DataUtil.verify(expect.getPlatformEnum(), actual.getPlatformEnum(),
				"验证OrderInfo.PlatformEnum");
		DataUtil.verify(expect.getPostCode(), actual.getPostCode(),
				"验证OrderInfo.PostCode");
		DataUtil.verify(expect.getPostPaidAmountOfCoupon(),
				actual.getPostPaidAmountOfCoupon(),
				"验证OrderInfo.PostPaidAmountOfCoupon");
		DataUtil.verify(expect.getPostPaidAmountOfGift(),
				actual.getPostPaidAmountOfGift(),
				"验证OrderInfo.PostPaidAmountOfGift");
		DataUtil.verifyDateEquals(expect.getPostPaidTime(),
				actual.getPostPaidTime(), "验证OrderInfo.PostPaidTime");
		DataUtil.verify(expect.getRealPaidAmountOfCash(),
				actual.getRealPaidAmountOfCash(),
				"验证OrderInfo.RealPaidAmountOfCash");
		DataUtil.verify(expect.getRealPaidAmountOfGift(),
				actual.getRealPaidAmountOfGift(),
				"验证OrderInfo.RealPaidAmountOfGift");
		DataUtil.verify(expect.getRealPay(), actual.getRealPay(),
				"验证OrderInfo.RealPay");
		DataUtil.verify(expect.getRealPostPay(), actual.getRealPostPay(),
				"验证OrderInfo.RealPostPay");
		DataUtil.verify(expect.getReceivePerson(), actual.getReceivePerson(),
				"验证OrderInfo.ReceivePerson");
		DataUtil.verify(expect.getRefund(), actual.getRefund(),
				"验证OrderInfo.Refund");
		DataUtil.verify(expect.getSellerLoginId(), actual.getSellerLoginId(),
				"验证OrderInfo.SellerLoginId");
		DataUtil.verify(expect.getSellerNote(), actual.getSellerNote(),
				"验证OrderInfo.SellerNote");
		DataUtil.verify(expect.isShangouOrder(), actual.isShangouOrder(),
				"验证OrderInfo.ShangouOrder");
		DataUtil.verify(expect.getStockStatus(), actual.getStockStatus(),
				"验证OrderInfo.StockStatus");
		DataUtil.verify(expect.getTelephone(), actual.getTelephone(),
				"验证OrderInfo.Telephone");
		DataUtil.verify(expect.getTitle(), actual.getTitle(),
				"验证OrderInfo.Title");
		DataUtil.verify(expect.getTotalPrice(), actual.getTotalPrice(),
				"验证OrderInfo.TotalPrice");
		DataUtil.verify(expect.getTradingId(), actual.getTradingId(),
				"验证OrderInfo.TradingId");
		DataUtil.verify(expect.getTradingStatus(), actual.getTradingStatus(),
				"验证OrderInfo.TradingStatus");
		DataUtil.verify(expect.getUseGiftAmount(), actual.getUseGiftAmount(),
				"验证OrderInfo.UseGiftAmount");
		DataUtil.verify(expect.getUserId(), actual.getUserId(),
				"验证OrderInfo.UserId");
		DataUtil.verify(expect.getBusynessTypeList(),
				actual.getBusynessTypeList(), "验证OrderInfo.BusynessTypeList");
		DataUtil.verify(expect.getCancelReason(), actual.getCancelReason(),
				"验证OrderInfo.CancelReason");
		DataUtil.verify(expect.isHaveUploadedIdCard(),
				actual.isHaveUploadedIdCard(), "验证OrderInfo.HaveUploadedIdCard");
		DataUtil.verify(
				expect.getIsNewCustomerOrder() == null ? false : expect
						.getIsNewCustomerOrder(),
				actual.getIsNewCustomerOrder() == null ? false : actual
						.getIsNewCustomerOrder(),
				"验证OrderInfo.IsNewCustomerOrder");
		DataUtil.verify(
				expect.getIsNewSellerOrder() == null ? false : expect
						.getIsNewSellerOrder(),
				actual.getIsNewSellerOrder() == null ? false : actual
						.getIsNewSellerOrder(), "验证OrderInfo.IsNewSellerOrder");
		DataUtil.verify(expect.getMainOrderId(), actual.getMainOrderId(),
				"验证OrderInfo.MainOrderId");
		DataUtil.verify(expect.isNeedUploadIdCard(),
				actual.isNeedUploadIdCard(), "验证OrderInfo.NeedUploadIdCard");
		DataUtil.verify(DataUtil.Booleann.GetValueOrDefault(expect
				.getPackageDelivery_DomesticDelivered()), DataUtil.Booleann
				.GetValueOrDefault(actual
						.getPackageDelivery_DomesticDelivered()),
				"验证OrderInfo.PackageDelivery_DomesticDelivered");
		DataUtil.verify(expect.getPaidAmountOfFreeCard(),
				actual.getPaidAmountOfFreeCard(),
				"验证OrderInfo.PaidAmountOfFreeCard");
		DataUtil.verify(expect.getPaidAmountOfYmtCoupon(),
				actual.getPaidAmountOfYmtCoupon(),
				"验证OrderInfo.PaidAmountOfYmtCoupon");
		DataUtil.verify(expect.getPayableAmount(), actual.getPayableAmount(),
				"验证OrderInfo.PayableAmount");
		DataUtil.verify(expect.getPromotionReducedAmount(),
				actual.getPromotionReducedAmount(),
				"验证OrderInfo.PromotionReducedAmount");
		DataUtil.verify(expect.getRealSettlementAmountOfCoupon(),
				actual.getRealSettlementAmountOfCoupon(),
				"验证OrderInfo.RealSettlementAmountOfCoupon");
		DataUtil.verify(expect.getRemarkLevel(), actual.getRemarkLevel(),
				"验证OrderInfo.RemarkLevel");
		DataUtil.verify(expect.getRiskVerifiedStatus(),
				actual.getRiskVerifiedStatus(),
				"验证OrderInfo.RiskVerifiedStatus");
		DataUtil.verify(expect.getSalesRefundStatus(),
				actual.getSalesRefundStatus(), "验证OrderInfo.SalesRefundStatus");
		DataUtil.verify(expect.getSellerCouponAmount(),
				actual.getSellerCouponAmount(),
				"验证OrderInfo.SellerCouponAmount");
		DataUtil.verify(expect.getSellerCouponCode(),
				actual.getSellerCouponCode(), "验证OrderInfo.SellerCouponCode");
		// DataUtil.verify(expect.isSupportLocalRefund(),
		// actual.isSupportLocalRefund(), "验证OrderInfo.SupportLocalRefund");
		DataUtil.verify(expect.getTotalPriceChange(),
				actual.getTotalPriceChange(), "验证OrderInfo.TotalPriceChange");
		DataUtil.verify(expect.getTotalSalesRefundAmount(),
				actual.getTotalSalesRefundAmount(),
				"验证OrderInfo.TotalSalesRefundAmount");
		DataUtil.verify(expect.getYmtCouponAmount(),
				actual.getYmtCouponAmount(), "验证OrderInfo.YmtCouponAmount");
		DataUtil.verify(expect.getYmtCouponCode(), actual.getYmtCouponCode(),
				"验证OrderInfo.YmtCouponCode");
	}

	private void verifyOrderItemList(OrderItemInfo exp, OrderItemInfo act,
			String expPid) {
		DataUtil.verify(exp.getAmount(), act.getAmount(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的Amount");
		DataUtil.verify(exp.getBondedArea(), act.getBondedArea(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的BondedArea");
		DataUtil.verify(exp.getCatalogId(), act.getCatalogId(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的CatalogId");
		DataUtil.verify(exp.getDescription(), act.getDescription(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的Description");
		DataUtil.verify(exp.getDiscount(), act.getDiscount(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的Discount");
		DataUtil.verify(exp.getFreight(), act.getFreight(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的Freight");
		DataUtil.verify(exp.getFreightFree(), act.getFreightFree(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的FreightFree");
		DataUtil.verify(exp.isCost(), act.isCost(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的IsCost");
		DataUtil.verify(exp.getItemType(), act.getItemType(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的ItemType");
		DataUtil.verify(exp.getLogisticsType(), act.getLogisticsType(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的LogisticsType");
		DataUtil.verify(exp.getOrderItemId(), act.getOrderItemId(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的OrderItemId");
		DataUtil.verify(exp.getPictureUrl(), act.getPictureUrl(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的PictureUrl");
		DataUtil.verify(exp.getPremium(), act.getPremium(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的Premium");
		DataUtil.verify(exp.getPrice(), act.getPrice(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的Price");
		DataUtil.verify(exp.getPriceType(), act.getPriceType(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的PriceType");
		DataUtil.verify(exp.getProductId(), act.getProductId(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的ProductId");
		DataUtil.verify(exp.getProductOriginalPrice(),
				act.getProductOriginalPrice(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的ProductOriginalPrice");
		DataUtil.verify(exp.getProductPrice(), act.getProductPrice(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的ProductPrice");
		DataUtil.verify(exp.getProductRefundChannel(),
				act.getProductRefundChannel(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的ProductRefundChannel");
		DataUtil.verify(exp.getPromotion(), act.getPromotion(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的Promotion");
		DataUtil.verify(exp.getPropertyInfo(), act.getPropertyInfo(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的PropertyInfo");
		// DataUtil.verify(exp.getReferenceUrl(), act.getReferenceUrl(),
		// "验证OrderInfo.OrderItemList中ProductId=["+expPid+"]的ReferenceUrl");
		DataUtil.verify(exp.getRefundBillNo(), act.getRefundBillNo(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的RefundBillNo");
		DataUtil.verify(exp.isSailProtected(), act.isSailProtected(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的SailProtected");
		// DataUtil.verify(exp.getSalesType(), act.getSalesType(),
		// "验证OrderInfo.OrderItemList中ProductId=[" + expPid
		// + "]的SalesType");
		DataUtil.verify(exp.getSellerCouponAmount(),
				act.getSellerCouponAmount(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的SellerCouponAmount");
		DataUtil.verify(exp.getSku(), act.getSku(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的Sku");
		DataUtil.verify(exp.getStockStatus(), act.getStockStatus(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的StockStatus");
		DataUtil.verify(exp.getSubProductCategoryId(),
				act.getSubProductCategoryId(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的SubProductCategoryId");
		DataUtil.verify(exp.isSupportRtnWithoutReason(),
				act.isSupportRtnWithoutReason(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的SupportRtnWithoutReason");
		DataUtil.verify(exp.getTariffType(), act.getTariffType(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的TariffType");
		DataUtil.verify(exp.getTitle(), act.getTitle(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的Title");
		DataUtil.verify(exp.getYmtCouponAmount(), act.getYmtCouponAmount(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的YmtCouponAmount");
		DataUtil.verify(exp.isPreSale(), act.isPreSale(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid + "]的PreSale");
		DataUtil.verify(exp.getThirdPartyDiscount(),
				act.getThirdPartyDiscount(),
				"验证OrderInfo.OrderItemList中ProductId=[" + expPid
						+ "]的ThirdPartyDiscount");
		if (null == exp.getOrderItemInfoExt()) {
			DataUtil.verify(true, act.getOrderItemInfoExt() == null,
					"验证ProductId=[" + expPid + "]的OrderItemInfoExt == null");
		} else {
			verifyOrderItemInfoExt(exp.getOrderItemInfoExt(),
					act.getOrderItemInfoExt(), expPid);
		}
	}

	private void verifyOrderItemInfoExt(OrderItemInfoExt expect,
			OrderItemInfoExt actual, String oid) {
		DataUtil.verify(expect.getActivityId(), actual.getActivityId(),
				"验证ProductId=[[" + oid + "]的OrderItemInfoExt.ActivityId");
		DataUtil.verify(expect.getActivityTemplateId(),
				actual.getActivityTemplateId(), "验证ProductId=[" + oid
						+ "]的OrderItemInfoExt.ActivityTemplateId");
		DataUtil.verify(expect.getGiftAvail4Reward(),
				actual.getGiftAvail4Reward(), "验证ProductId=[" + oid
						+ "]的OrderItemInfoExt.GiftAvail4Reward");
	}

	private void ConstructExpectedResponse(GetSingleOrderInfoResponse response) {

		Order order = new OrderQueryWapper().findById(gsoibean.getOrderId());

		if (null != order
				&& (gsoibean.getUserId() == -1
						|| gsoibean.getUserId() == order.getUserId() || gsoibean
						.getUserId() == order.getSellerId()))
			response.setOrderInfo(SingleOrderInfoBuilder.convertOrder(order,
					productClient, sellerInfoClient));
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSingleOrderInfo_001() {
		Logger.start(true, "获取单个订单信息成功");
		try {
			Logger.comment("准备订单数据");
			TradingServiceResp placeOrder = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long userId = placeOrder.getUserId();
			Logger.comment("完成准备订单数据");
			Thread.sleep(1000);
			gsoibean.setOrderId(orderId);
			gsoibean.setUserId(userId);
			// 发送请求
			String param = FormatUtil.beanToHttpString(gsoibean, true, false);
			gsoicall.setData(param);
			gsoicall.callService();
			Logger.verifyEquals(ECode.SUCCESS, gsoicall.getCode(), "验证Code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSingleOrderInfo_002() {
		Logger.start(true, "用户id为0");
		try {
			gsoibean.setOrderId(105293318);
			gsoibean.setUserId(0);
			// 发送请求
			String param = FormatUtil.beanToHttpString(gsoibean, true, false);
			gsoicall.setData(param);
			gsoicall.callService();
			Logger.comment("gsoicall send:" + gsoicall.getEntityString());
			Logger.comment("gsoicall response:" + gsoicall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, gsoicall.getCode(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSingleOrderInfo_003() {
		Logger.start(true, "订单编号id为空");
		try {
			gsoibean.setUserId(3793376);
			// 发送请求
			String param = FormatUtil.beanToHttpString(gsoibean, true, false);
			gsoicall.setData(param);
			gsoicall.callService();
			Logger.comment("gsoicall send:" + gsoicall.getEntityString());
			Logger.comment("gsoicall response:" + gsoicall.getReturnData());
			Logger.verifyEquals(ECode.FAILED400, gsoicall.getCode(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetSingleOrderInfo_004() {
		Logger.start(true, "用户id不存在");
		try {
			// 创建订单
			/*
			 * Map map = new OrderCallService().createOrder(); JSONArray
			 * OrderIds = (JSONArray) map.get("OrderIds"); int OrderId =
			 * OrderIds.getInt(0); int UserId = (Integer) map.get("UserId");
			 */
			gsoibean.setOrderId(105293318);
			gsoibean.setUserId(1);
			// 发送请求
			String param = FormatUtil.beanToHttpString(gsoibean, true, false);
			gsoicall.setData(param);
			gsoicall.callService();
			Logger.verifyEquals(ECode.SUCCESS, gsoicall.getCode(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSingleOrderInfo_008() {
		Logger.start(true, "获取完成退款状态的订单信息成功");
		try {
			Logger.comment("准备订单数据");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			com.ymatou.iapi.optrade.resp.Order order = placeOrderResp
					.getOrderList().get(0);

			long userId = placeOrderResp.getUserId();
			Long orderId = order.getOrderId();
			long sellerId = order.getSellerId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			ApplyRefundReq applyRefundReq = RefundService.applyRefund(order);

			Thread.sleep(5000);

			AgreeRefundReq salesrefundsuccessReq = new AgreeRefundReq();
			AgreeRefundCall salesrefundsuccessCall = new AgreeRefundCall();

			salesrefundsuccessReq.setOrderId(orderId);

			int i = 0;
			for (SalesRefundInfoVo salesRefundInfoVo : applyRefundReq
					.getSalesRefundInfoList()) {

				salesrefundsuccessReq.setRefundBillNo(salesRefundInfoVo
						.getRefundBillNo());
				salesrefundsuccessCall.setData(salesrefundsuccessReq);

				Logger.comment(String.format("orderid: %s 第 %s 个商品 退款执行",
						orderId, i + 1));

				salesrefundsuccessCall.callService();

				Logger.verifyEquals("true",
						salesrefundsuccessCall.getString("success"),
						"验证退货退款成功返回");
				i++;
			}

			Thread.sleep(5000);

			Logger.comment("完成准备订单数据");
			gsoibean.setOrderId(orderId);
			gsoibean.setUserId(userId);
			// 发送请求
			String param = FormatUtil.beanToHttpString(gsoibean, true, false);
			gsoicall.setData(param);
			gsoicall.callService();

			Logger.verifyEquals(ECode.SUCCESS, gsoicall.getCode(), "验证Code");
			this.verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSingleOrderInfo_009() {
		Logger.start(true, "获取取消状态的订单信息成功");
		try {
			Logger.comment("准备订单数据");
			TradingServiceResp placeOrder = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();

			// 取消订单
			TradingCallService.cancelOrder(orderId,
					CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);

			TradingSyncService.getSyncResult(orderId);
			Logger.comment("完成准备订单数据");
			gsoibean.setOrderId(orderId);
			gsoibean.setUserId(userId);
			// 发送请求
			String param = FormatUtil.beanToHttpString(gsoibean, true, false);
			gsoicall.setData(param);
			gsoicall.callService();
			Logger.verifyEquals(ECode.SUCCESS, gsoicall.getCode(), "验证Code");
			this.verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSingleOrderInfo_010() {
		Logger.start(true, "获取发货状态的订单信息成功");
		try {
			Logger.comment("准备订单数据");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLogisticsType(LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			long userId = placeOrderResp.getUserId();

			long tradingId = placeOrderResp.getTradingId();

			BigDecimal useAccountAmount = placeOrderResp.getPayableAmount();

			TradingCallService.payOrder(userId, useAccountAmount, tradingId);

			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);

			TradingSyncService.getSyncResult(orderId);
			Logger.comment("完成准备订单数据");
			gsoibean.setOrderId(orderId);
			gsoibean.setUserId(userId);
			// 发送请求
			String param = FormatUtil.beanToHttpString(gsoibean, true, false);

			gsoicall.setData(param);
			gsoicall.callService();
			Logger.verifyEquals(ECode.SUCCESS, gsoicall.getCode(), "验证Code");
			this.verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSingleOrderInfo_011() {
		Logger.start(true, "获取确认收货状态的订单信息成功");
		try {
			Logger.comment("准备订单数据");
			// 创建一个拼邮的订单
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			long userId = placeOrderResp.getUserId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			TradingSyncService.getSyncResult(orderId);
			Logger.comment("完成准备订单数据");
			gsoibean.setOrderId(orderId);
			gsoibean.setUserId(userId);
			// 发送请求
			String param = FormatUtil.beanToHttpString(gsoibean, true, false);

			gsoicall.setData(param);
			gsoicall.callService();
			Logger.verifyEquals(ECode.SUCCESS, gsoicall.getCode(), "验证Code");
			this.verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetSingleOrderInfo_016() {
		Logger.start(true, "获取单个订单信息成功");
		try {
			/*
			 * Logger.comment("准备订单数据"); int sellerId =
			 * Integer.valueOf(EnvSetup.getData("SellerId")); int userId =
			 * Integer.valueOf(EnvSetup.getData("BuyUserId")); OrderCreate o =
			 * new OrderCreate(); C2COrderInfoExt order =
			 * o.create1_M2cOrder(userId, sellerId); Logger.comment("完成准备订单数据");
			 * Thread.sleep(1000);
			 */
			gsoibean.setOrderId(2395528699L);
			gsoibean.setUserId(20325187);
			// 发送请求
			String param = FormatUtil.beanToHttpString(gsoibean, true, false);
			gsoicall.setData(param);
			gsoicall.callService();
			Logger.verifyEquals(ECode.SUCCESS, gsoicall.getCode(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}